package com.qyhl.webtv.module_news.news.nanbu;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

public class NanBuNewsModel implements NanBuNewsContract.NanBuNewsModel {
    private NanBuNewsPresenter mPresenter;

    NanBuNewsModel(NanBuNewsPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getData(String catalogId,String page) {
        EasyHttp.get(NewsUrl.GET_NANBU_NEWS)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("catalogId", catalogId)
                .params("page", page)
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取列表失败，请重新尝试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<NewsBean> newsBeans) {
                        if (newsBeans != null && newsBeans.size() > 0) {
                            mPresenter.setListData(newsBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });

    }
}
